package o;

import com.huawei.android.fsm.HwFoldScreenManagerEx;
import com.huawei.android.util.NoExtAPIException;
import com.huawei.appgallery.aguikit.device.HwFoldDisplayModeListener;

public class ayz {
    private static ayz ˎ;
    private static final Object ˏ = new Object();
    private boolean ʼ = false;
    private HwFoldDisplayModeListener ˊ;
    private int ˋ = 0;
    private int ॱ = -1;

    public static ayz ˋ() {
        ayz o_ayz;
        synchronized (ˏ) {
            if (ˎ == null) {
                ˎ = new ayz();
            }
            o_ayz = ˎ;
        }
        return o_ayz;
    }

    public static boolean ˏ() {
        boolean z = false;
        try {
            z = HwFoldScreenManagerEx.isFoldable();
        } catch (SecurityException e) {
            ayv.ˎ.ˊ("HwFoldScreenDeviceUtils", "isFoldable SecurityException: " + e.toString());
        } catch (NoExtAPIException e2) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "isFoldable NoExtAPIException: " + e2.toString());
        } catch (Exception e3) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "isFoldable Exception" + e3.toString());
        } catch (Throwable th) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "isFoldable Throwable" + th.toString());
        }
        ayv.ˎ.ˋ("HwFoldScreenDeviceUtils", "isFoldable=" + z);
        return z;
    }

    public boolean ˎ() {
        return this.ॱ == 1;
    }

    public int ˊ() {
        return this.ॱ;
    }

    public void ˏ(int i) {
        this.ॱ = i;
    }

    private static int ʽ() {
        int i = 0;
        try {
            i = HwFoldScreenManagerEx.getDisplayMode();
        } catch (SecurityException e) {
            ayv.ˎ.ˊ("HwFoldScreenDeviceUtils", "getDisplayMode SecurityException: " + e.toString());
        } catch (NoExtAPIException e2) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "getDisplayMode NoExtAPIException: " + e2.toString());
        } catch (Exception e3) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "getDisplayMode Exception" + e3.toString());
        } catch (Throwable th) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "getDisplayMode Throwable" + th.toString());
        }
        ayv.ˎ.ˋ("HwFoldScreenDeviceUtils", "getDisplayMode=" + i);
        return i;
    }

    public void ˊ(HwFoldDisplayModeListener hwFoldDisplayModeListener) {
        if (hwFoldDisplayModeListener == null) {
            ayv.ˎ.ˊ("HwFoldScreenDeviceUtils", "startMonitorDisplayMode: this HwFoldDisplayModeListener.");
        } else if (this.ॱ == -1) {
            if (ˏ()) {
                this.ॱ = 1;
                this.ˋ = ʽ();
                this.ˊ = hwFoldDisplayModeListener;
                ˎ(this.ˊ);
                this.ʼ = true;
                return;
            }
            this.ॱ = 0;
            ayv.ˎ.ˎ("HwFoldScreenDeviceUtils", "startMonitorDisplayMode: this device is not foldable.");
        } else if (this.ॱ == 0) {
            ayv.ˎ.ˎ("HwFoldScreenDeviceUtils", "startMonitorDisplayMode: this device is not foldable.");
        } else if (this.ॱ == 1 && !this.ʼ) {
            ˎ(this.ˊ);
        }
    }

    public void ॱ() {
        if (this.ॱ == 1 && this.ˊ != null && this.ʼ) {
            ॱ(this.ˊ);
            this.ʼ = false;
        }
    }

    private void ˎ(HwFoldDisplayModeListener hwFoldDisplayModeListener) {
        try {
            HwFoldScreenManagerEx.registerFoldDisplayMode(hwFoldDisplayModeListener);
        } catch (SecurityException e) {
            ayv.ˎ.ˊ("HwFoldScreenDeviceUtils", "registerFoldDisplayMode SecurityException: " + e.toString());
        } catch (NoExtAPIException e2) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "registerFoldDisplayMode NoExtAPIException: " + e2.toString());
        } catch (Exception e3) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "registerFoldDisplayMode Exception: " + e3.toString());
        } catch (Throwable th) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "registerFoldDisplayMode Throwable: " + th.toString());
        }
    }

    private void ॱ(HwFoldDisplayModeListener hwFoldDisplayModeListener) {
        try {
            HwFoldScreenManagerEx.unregisterFoldDisplayMode(hwFoldDisplayModeListener);
        } catch (SecurityException e) {
            ayv.ˎ.ˊ("HwFoldScreenDeviceUtils", "unregisterFoldDisplayMode SecurityException: " + e.toString());
        } catch (NoExtAPIException e2) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "unregisterFoldDisplayMode NoExtAPIException: " + e2.toString());
        } catch (Exception e3) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "unregisterFoldDisplayMode Exception: " + e3.toString());
        } catch (Throwable th) {
            ayv.ˎ.ˏ("HwFoldScreenDeviceUtils", "unregisterFoldDisplayMode Throwable: " + th.toString());
        }
    }

    public int ʼ() {
        return this.ˋ;
    }

    public void ˋ(int i) {
        this.ˋ = i;
    }
}
